<template>
  <!-- 头部 -->
  <el-container class="home_container">
    <el-header>
      Header
      <el-button type="info" @click="handel">退出</el-button>
    </el-header>
    <!-- 侧边 -->
    <el-container >
      <el-aside :width="isCollapse? '64px':'200px'">
        <div class="toggle_button"  @click="toggleCollapse">|||</div>
        <!--  -->
        <el-menu background-color="#333744" text-color="#fff" active-text-color="#409eff" unique-opened :collapse=isCollapse :collapse-transition='false' router :default-active='saveActive'>
          <!-- 一级菜单 -->
          <el-submenu :index="item.id + ''" :key="item.id" v-for="item in menuList">
            <!-- 一级菜单的模板 -->
            <template slot="title">
              <!-- i是图标 -->
              <i :class="iconsList[item.id]"></i>
              <!-- span是文本 -->
              <span>{{item.authName}}</span>
            </template>
            <!-- 二级菜单 -->
            <!-- <el-menu-item index="1-4-1">选项1</el-menu-item> -->
            
            <el-menu-item :index="'/' + subitem.path + ''" :key="subitem.id" v-for="subitem in item.children" @click="saveactive('/' + subitem.path)">
              <template slot="title">
                <!-- i是图标 -->
                <i class="el-icon-menu"></i>
                <!-- span是文本 -->
                <span>{{subitem.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 内容 -->
      <el-main>
          <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
  <!-- 分页 -->
  
</template>
<script>
export default {
  data() {
    return {
      saveActive:'',
      menuList: [],
      iconsList: {
        125: 'iconfont icon-user',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-3702mima',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao'
      },
      isCollapse:false
    }
  },
  created() {
    this.getMenuList()
    this.saveActive = window.sessionStorage.getItem('saveactive')
  },
  methods: {
    handel() {
      sessionStorage.clear()
      this.$router.push('/login')
    },
    getMenuList: async function() {
      const { data: data } = await this.$http.get('/menus')
      console.log(data.data)
      this.menuList = data.data
    },
    toggleCollapse(){
        this.isCollapse = !this.isCollapse
    },
    saveactive(val){
        console.log(val);
        // alert(1)
        
        window.sessionStorage.setItem('saveactive',val)
        this.saveActive = val
    }
  }
}
</script>
<style lang='css' scoped>
.el-menu-item {
    margin-left: 20px;
}
button {
  float: right;
  margin-top: 10px;
}
.home_container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  color: #333;
  text-align: center;
  line-height: 60px;
}
 
.el-aside {
  background-color: #333744;
  color: #333;
  text-align: center;
  /* line-height: 200px; */
}

.el-main {
  background-color: #eaedf1;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.iconfont {
  margin-right: 10px;
}
.el-menu {
    border-right: none
}
.toggle_button {
    background-color: #4a5064;
    line-height: 26px;
    font-size: 10px;
    color: #fff;
    letter-spacing: 0.2em;
    cursor: pointer;
}
</style>